﻿#ifndef TLVCODETASK_H
#define TLVCODETASK_H

#include <QProcess>
#include "ITask.h"
#include "services/Process/APIBridgeCom.h"


class TlvCodeTask : public ITask
{
    Q_OBJECT
public:
    enum CodeType {
        JavaScript,  // 内置nodejs可以运行JavaScript
        Python       // Python需要用户自行安装环境
    };

    explicit TlvCodeTask(QObject *parent = nullptr);
    ~TlvCodeTask();

    void stop();
    void setCode(const QString& code);
    void setCodeType(CodeType type);

    static TlvCodeTask* instance();

signals:
    void hasLog(const QString& msg);

private:
    void startProcess(const QString& proc, const QStringList& args);
    void runTask() override;
    void runJs();
    void runPython();

private:
    QString m_code;
    QProcess *m_process;
    APIBridgeCom* m_ipc;
    CodeType m_codeType = JavaScript;
};

#endif // TLVCODETASK_H
